00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _adjacency_list_hpp_
00029 #define _adjacency_list_hpp_
00030
00031 #include <utility>
00032 #include <vector>
00033 #include <gridpack/parallel/distributed.hpp>
00034 #include <gridpack/utilities/uncopyable.hpp>
00035
00036 namespace gridpack {
00037 namespace network {
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 class AdjacencyList :
00056 public parallel::Distributed,
00057 private utility::Uncopyable
00058 {
00059 public:
00060
00061
00062 typedef unsigned int Index;
00063
00064
00065 typedef std::vector<Index> IndexVector;
00066
00067
00068 static const Index bogus;
00069
00070
00071 AdjacencyList(const parallel::Communicator& comm);
00072
00073
00074 AdjacencyList(const parallel::Communicator& comm,
00075 const int& local_nodes, const int& local_edges);
00076
00077
00078 ~AdjacencyList(void);
00079
00080
00081 void add_node(const Index& global_index, const Index& original_index)
00082 {
00083 p_global_nodes.push_back(global_index);
00084 p_original_nodes.push_back(original_index);
00085 }
00086
00087
00088
00089 void add_edge(const Index& edge_index,
00090 Index node_index_1,
00091 Index node_index_2)
00092 {
00093 p_Edge tmp;
00094 tmp.index = edge_index;
00095 tmp.original_conn = std::make_pair(node_index_1, node_index_2);
00096 p_edges.push_back(tmp);
00097 }
00098
00099
00100 void get_global_edge_ids(int idx, Index *node_index_1, Index *node_index_2) const
00101 {
00102 *node_index_1 = p_edges[idx].global_conn.first;
00103 *node_index_2 = p_edges[idx].global_conn.second;
00104 }
00105
00106
00107 size_t nodes(void) const
00108 {
00109 return p_global_nodes.size();
00110 }
00111
00112
00113 Index node_index(const int& local_index) const;
00114
00115
00116 size_t edges(void) const
00117 {
00118 return p_edges.size();
00119 }
00120
00121
00122 Index edge_index(const int& local_index) const;
00123
00124
00125 void edge(const int& local_index, Index& node1, Index& node2) const;
00126
00127
00128 void ready(void);
00129
00130
00131 void node_neighbors(const int& local_index,
00132 IndexVector& global_neighbor_indexes) const;
00133
00134
00135 size_t node_neighbors(const int& local_index) const;
00136
00137 protected:
00138
00139 typedef std::pair<Index, Index> p_NodeConnect;
00140 typedef std::pair<bool, bool> p_Connected;
00141
00142 struct p_Edge {
00143 Index index;
00144 p_NodeConnect original_conn;
00145 p_NodeConnect global_conn;
00146 p_Connected found;
00147 p_Edge() : index(0), original_conn(), global_conn(), found(false, false) {}
00148 };
00149 typedef std::vector<p_Edge> p_EdgeVector;
00150
00151 typedef std::vector<IndexVector> p_Adjacency;
00152
00153
00154 IndexVector p_global_nodes;
00155
00156
00157 IndexVector p_original_nodes;
00158
00159
00160 p_EdgeVector p_edges;
00161
00162
00163 p_Adjacency p_adjacency;
00164
00165
00166 };
00167
00168 }
00169 }
00170
00171
00172 #endif